<?php
/***********************************************************************
 * @package    IvanEngine
 * @subpackage Core
 * @author     Ivan <ivanzx@msn.com>
 * @created    2010-05-13
 ***********************************************************************/
if(defined("IVANENGINE_CORE_STL_STACK"))
	die("Redefinition macro in :".__FILE__."(".__LINE__.")");
define("IVANENGINE_CORE_STL_STACK", true);

require_once (dirname(__FILE__).'/../Base.php');

class CStack extends CBase implements Serializable
{
	protected $m_array	= array();
	
	public function __construct() 
	{
		parent::__construct();
	}

	public function __destruct()
	{
		unset($this->m_array);
		parent::__destruct();
	}
	
	public function Push($val)
	{
		array_push($this->m_array, $val);
	}
	
	public function Pop()
	{
		if($this->IsEmpty())
			return null;
			
		return array_pop($this->m_array);
	}
	
	public function Size()
	{
		return count($this->m_array);
	}
	
	public function IsEmpey()
	{
		return $this->Size() == 0;
	}
	
	public function & Top()
	{
		return $this->m_array[$this->Size()-1];
	}
	
	public function Clear()
	{
		unset($this->m_array);
		$this->m_array	= array();
	}
	
  	public function serialize()
  	{
    	return serialize($this->m_array);
  	}
  	
  	public function unserialize($serialized)
  	{
    	$this->m_array = unserialize($serialized);
  	}
}

?>
